﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;

namespace KinTN_WMS_CL.Extensions
{
    public class ListConversion
    {
        public List<DataGridTextColumn> CreateDynamicColumns<T>()
        {
            List<DataGridTextColumn> dataGridTextColumns = new List<DataGridTextColumn>();
            var properties = typeof(T).GetProperties();
            foreach (var property in properties)
            {
                var displayAttribute = property.GetCustomAttributes(typeof(DisplayAttribute), false)
                                               .Cast<DisplayAttribute>()
                                               .FirstOrDefault();

                var column = new DataGridTextColumn
                {
                    Header = displayAttribute?.Name ?? property.Name,
                    Binding = new System.Windows.Data.Binding(property.Name),
                    Width = DataGridLength.Auto,
                };
                dataGridTextColumns.Add(column);
            }
            return dataGridTextColumns;
        }
    }
}
